package nix.wildcard;

import java.util.ArrayList;
import java.util.List;

public class Demo1 {

	public void fun0() {
		Object[] objectArray = new String[10];
		//List<Object> objectList = new ArrayList<String>();
	}

	public void fun1() {
		
		List<Integer> integerList = new ArrayList<Integer>();
		print1(integerList);
		
		List<String> stringList = new ArrayList<String>();
		print2(stringList);
	}
	
	public void print1(List<? extends Object> list) {
		
	}

	public void fun2() {
		
		List<Integer> integerList = new ArrayList<Integer>();
		print2(integerList);
		
		List<String> stringList = new ArrayList<String>();
		print2(stringList);
	}
	
	/*
	 * 无界通配（?）：参数和返回值为泛型的方法均不能使用
	 */
	public void print2(List<?> list) {
		//list.add(new Integer(100));
		//Integer i = list.get(0);
		Object o = list.get(0);
	}

	public void fun3() {
		
		List<Integer> integerList = new ArrayList<Integer>();
		print3(integerList);
		
		List<Long> longList = new ArrayList<Long>();
		print3(longList);
	}
	
	/**
	 * 子类限定通配（? extends Object）：参数为泛型的方法不能使用
	 */
	public void print3(List<? extends Number> list) {
		//list.add(new Integer(100));
		Number n = list.get(0);
	}
	
	public void fun4() {
		List<Integer> integerList = new ArrayList<Integer>();
		print4(integerList);
		
		List<Number> numberList = new ArrayList<Number>();
		print4(numberList);
		
		List<Long> longList = new ArrayList<Long>();
		//print4(longList);
	}
	
	/**
	 * 父类限定通配（? super Integer）：返回值为泛型的方法不能使用
	 */
	public void print4(List<? super Integer> list) {
		list.add(new Integer(100));
		//Integer i = list.get(0);
		Object o = list.get(0);
	}
}
